home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Blue / MoreStrings.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  4.5 KB  |  159 lines  |  [TEXT/CWIE]

  1.  
  2. #pragma once
  3.  
  4. #ifndef __MORESTRINGS__
  5. #define __MORESTRINGS__
  6.  
  7. #include "MoreAEM.h"
  8.  
  9. #include <Types.h>
  10. #include <TextUtils.h>
  11.  
  12. enum
  13. {
  14.     kStringStart = 0,
  15.     kStringEnd = 0x7FFFFFFF,
  16.     kStringAllocationChunk    = 32,
  17.     kSubstringNotFound        = -1
  18. };
  19.  
  20.  
  21. //========================================================================================
  22. // CLASS TString
  23. //========================================================================================
  24.  
  25. class TString
  26. {
  27. public:
  28.     TString();
  29.     TString(const TString&);
  30.     TString(const TDescriptor&);
  31.     
  32.     TString(UInt32 maximumSize);
  33.     TString(unsigned char* stringExternalStorage, UInt32 maximumSize, UInt32 currentSizeInBytes = 0, ScriptCode stringScript = smSystemScript, LangCode stringLanguage = scriptDefLang);
  34.     TString(unsigned char*); // Str255 assumed
  35.  
  36.     
  37.     ~TString();
  38.     
  39.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  40.     //::  Common methods
  41.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  42.  
  43.     operator TDescriptor() const;
  44.     
  45.     TString& operator=(const TString&);
  46.     TString& operator=(const TDescriptor& desc);
  47.     
  48.     Boolean operator==(const TString& rhs) const { return this->ExactlyEqual(rhs); }
  49.     
  50.     UInt32                    StringLength() const;
  51.     UInt32                    SizeInBytes() const;
  52.     UInt32                    MaximumSizeInBytes() const;
  53.     
  54.     Boolean                    Empty() const;
  55.     void                    ClearString();
  56.         
  57.     SInt16                    CompareStringOrder(const TString& stringToCompare) const;
  58.     Boolean                    Equal(const TString&) const;
  59.     Boolean                    ExactlyEqual(const TString&) const;
  60.     Boolean                    NearlyEqual(const TString&) const;
  61.  
  62.     SInt32                    FindOffset(const TString& searchPattern) const;
  63.     Boolean                    Contains(const TString& searchPattern) const;
  64.     
  65.     void                    Delete(UInt32 destStartIndex, UInt32 destEndIndex);
  66.     Boolean                    InsertAfter(UInt32 destStartIndex, const TString& replaceWith);
  67.     void                    Replace(UInt32 destStartIndex, UInt32 destEndIndex, const TString& replaceWith);
  68.     void                    Append(const TString&);
  69.     void                    Prefix(const TString&);
  70.     
  71.     void                    ConvertToStr255(Str255 destination);
  72.     
  73.  
  74.     operator const unsigned char*() const { ((TString*)this)->ExpandToFit(256); return fStr; }
  75.     operator unsigned char*() { ((TString*)this)->ExpandToFit(256); return fStr; }
  76.  
  77.     const unsigned char*    TextStart() const { return &fStr[1]; }
  78.     unsigned char*            TextStart() { return &fStr[1]; }
  79.     
  80.     ScriptCode                StringScript() const { return fStringScript; }
  81.     LangCode                StringLanguage() const { return fStringLanguage; }
  82.     
  83.  
  84. protected:
  85.  
  86.  
  87.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  88.     //::  protected methods
  89.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  90.  
  91.     Boolean                    Equivalent(const TString& compareWith) const;
  92.  
  93.     void                    SetLength(UInt32 newLength);
  94.     void                    CorrectInternalLength() const;
  95.     void                    ExpandToFit(UInt32 spaceRequired);
  96.  
  97.     
  98.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  99.     //::  Fields
  100.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  101.     
  102. protected:
  103.     
  104.     //
  105.     // Points to a length-byte + string (pascal format string)
  106.     // If the actual length of the string is longer than
  107.     // 255 bytes, then the length byte will be 255.
  108.     //
  109.     unsigned char*            fStr;
  110.  
  111.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  112.     //::  A little bit less than 16 bytes follows...
  113.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  114.  
  115.     //
  116.     // String script and language
  117.     //
  118.     ScriptCode                fStringScript;
  119.     LangCode                fStringLanguage;
  120.                 
  121.     //
  122.     // Keep track of important information
  123.     // about the string we point to
  124.     //
  125.     UInt32                    fActualSizeInBytes;
  126.     UInt32                    fMaximumSizeInBytes;
  127.     Boolean                    fStorageAllocatedInHeap;
  128.     
  129. };
  130.  
  131. enum
  132. {
  133.     kStackBasedStringStorageUnits = 256
  134. };
  135.  
  136. //========================================================================================
  137. // CLASS TStackBasedString
  138. //========================================================================================
  139.  
  140. class TStackBasedString : public TString
  141. {
  142. public:
  143.  
  144.     TStackBasedString() : TString(fStringStorage, kStackBasedStringStorageUnits * sizeof(unsigned char)) { fStringStorage[0] = 0; }
  145.     TStackBasedString(const TString&);
  146.  
  147.     TString& operator=(const TString& rhs)                { return TString::operator=(rhs); }
  148.     TString& operator=(const TDescriptor& desc)            { return TString::operator=(desc); }
  149.     
  150.     Boolean operator==(const TString& rhs) const        { return TString::operator==(rhs); }
  151.  
  152. protected:
  153.  
  154.     unsigned char            fStringStorage[kStackBasedStringStorageUnits];
  155.  
  156. };
  157.  
  158. #endif
  159.